// 函数式编程思想
// createRouter：创建router实例对象,类比之前的new操作
//  createWebHistory：创建出来的history模式的路由对象
import { createRouter, createWebHistory } from 'vue-router'
import Layout from '@/views/layout'
import Home from '@/views/home'
import Category from '@/views/category'
import SubCategory from '@/views/category/subCategory.vue'
import Detail from '@/views/detail'
import Login from '@/views/login'
import Cart from '@/views/cart'
import SettleMent from '@/views/settlement'

// 补充
// 整个页面发生变化 一般是一级路由
// 局部页面发生变化 一般是二级路由

const routes = [
  {
    path: '/login',
    component: Login
  },
  {
    path: '/',
    component: Layout,
    children: [
      {
        // ''等同于重定向
        path: '',
        component: Home
      },
      {
        name: 'category',
        path: 'category/:id',
        component: Category
      },
      {
        name: 'subCategory',
        path: 'category/sub/:id',
        component: SubCategory
      },
      {
        path: 'detail/:id',
        component: Detail
      },
      {
        path: 'cart',
        component: Cart
      },
      {
        path: 'settle',
        component: SettleMent
      }
    ]
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL), // 路由模式切换需要调用方法
  routes // 一一对应
})
// 导出router实例
export default router
